/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.edu.ucuenca.pagina_asos.controller.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.component.UIViewParameter;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewMetadata;

/**
 *
 * @author Marcelo
 */
public class Urls {

    public static String subdominioActual() {
        String direccionPrincipal = FacesContext.getCurrentInstance().getExternalContext().getRequestServerName();
        String subdominio = direccionPrincipal.split("\\.")[0];
        return subdominio;
    }

    public static String parametrosActuales() {
        Collection<UIViewParameter> viewParams = ViewMetadata.getViewParameters(FacesContext.getCurrentInstance().getViewRoot());

        String url = "";
        for (UIViewParameter viewParam : viewParams) {
            try {
                String name = viewParam.getName();
                Object value = viewParam.getValue();
                String valueEncoded = URLEncoder.encode(value+"","UTF-8");
                
                url += "&" + name + "=" + valueEncoded;
                // ...
            } catch (UnsupportedEncodingException ex) {
                Logger.getLogger(Urls.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        return url;
    }
}
